#include <QtGui/QApplication>
#include "testbase.h"

static bool initdatabase();


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
    QFont font("Arial",10,QFont::Normal,FALSE);
    //QFont font("unifont",16,50,FALSE,QFont::Unicode);
    a.setFont(font);
    if (!initdatabase())
        return 1;
    //MainWindow w;
    testbase w;
    w.move((QApplication::desktop()->width()- w.width())/2, (QApplication::desktop()->height() - w.height())/2);
    w.show();


    return a.exec();
}
static bool initdatabase()
{
    QSqlDatabase db=QSqlDatabase::addDatabase("QSQLITE");
    //m_db->addDatabase("QSQLITE");
    //db.setDatabaseName(":memory:");
    //qDebug()<<QCoreApplication::applicationDirPath()+".//ediary.db";
    #ifdef  WIN32 //windows平台下的实现
       db.setDatabaseName("D:/MyWorks/QT/mytestbase/testbase.db");
    #else
       db.setDatabaseName("/home/henry/Works/QT/mytestbase/testbase.db");
    #endif

    if (!db.open()) {
        QMessageBox::critical(0, qApp->tr("Cannot open database"),
            qApp->tr("Unable to establish a database connection.\n"
                     "This example needs SQLite support. Please read "
                     "the Qt SQL driver documentation for information how "
                     "to build it.\n\n"
                     "Click Cancel to exit."), QMessageBox::Cancel);
        qDebug()<<"initdatabase failed"<<db.lastError();
        return false;}
        else
        {

            qDebug()<<"successfull"<<db.lastError();
            return true;
        }

}
